<?php defined("MAIN_DIR") or die("No direct access");

if ($route->getPath(3) != "") {
	require_once APP."poll.php";
	die;
}

$answers_query = "select * from `answers`";
$ua_count = mysql_fetch_array(mysql_query("select COUNT(`ua_id`) as `count` from `user_answers`"));

$polls_query = "select `P`.*,COUNT(`UA`.`ua_id`) as `count` from `poll` as `P` left join `user_answers` as `UA` on `P`.`poll_id` = `UA`.`poll_id` group by `P`.`poll_id` order by `poll_id`";

$limit = 5; // количество вопросов на странице

$polls_result = mysql_query($polls_query);
$count = mysql_num_rows($polls_result);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$polls_query .= " limit $start_list,$limit";
$polls_result = mysql_query($polls_query);
$polls_count = mysql_num_rows($polls_result);

$head_title = "Опросы - «Банки России»";

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1>Опросы</h1>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td align="left" valign="top" class="banki_main_col">
			<div class="golosovanie_info">Нам важно знать ваше мнение. Примите участие в интернет-опросах нашего проекта</div>
			<div id="oprosy_table">
				<div>
					<table width="100%" border="0" cellpadding="8" cellspacing="0">
						<tr>
							<td><strong>Всего ответов</strong></td>
							<td width="26%"><strong><?php echo $ua_count['count']; ?></strong></td>
						</tr><?php
						while ($polls_row = mysql_fetch_array($polls_result))
						{
							?><tr>
								<td><a href="<?php echo "/$c_name";?>/polls/<?php echo $polls_row['poll_id'] ?>"><?php echo $polls_row['text'] ?></a></td>
								<td><?php
									echo $polls_row['count'];
								?></td>
							</tr><?php
						}
					?></table>
				</div>
				<?php require_once APP."pageskin.php"; ?>
			</div>
		</td>
		<td width="218" align="left" valign="top"><?php
			require_once APP."rating_column.php";
			require_once APP."vacancy_column.php";
		?></td>
	</tr>
</table>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '7' limit 1"));
				$text = getRichText($info['text']);
				echo "<h2>$info[header]</h2>";
				echo "<p>$text</p>";
			?></td>
		</tr>
	</table>
</div>
<?php require_once APP.FOOTERFILE; ?>